const Router = require("koa2-router");
const { placeOrders } = require("./controller/pay");
const router = new Router();


router.get("/", async (ctx) => {
  ctx.body = {
    code: 200,
    message: "接口服务正常！",
    data: [
      {
        title: "下单接口",
        url: "/pay/placeOrder",
        methods: "POST",
        params: {
          openid: "获取支付用户openid",
          total: "total：支付金额1代表1分",
          description: "支付商品描述",
          out_trade_no: "商户订单号",
        },
      },
    ],
  };
});

/**
 * @swagger
 * /pay/placeOrder:
 *   post:
 *     description: 微信支付统一下单接口
 *     parameters: 
 *       - name: openid
 *         in: input
 *         required: true
 *         type: string
 *         description: 前台获取用户openid 需先登陆获取code 然后在请求获取openid
 *       - name: total
 *         in: input
 *         required: true
 *         type: string
 *         description: 支付金额1代表1
 *       - name: description
 *         in: input
 *         required: true
 *         type: string
 *         description: 商品描述信息
 *       - name: out_trade_no
 *         in: input
 *         required: true
 *         type: string
 *         description: 商家唯一订单号支持大小写字母数字不要写特殊符号不超过32位字符
 *     responses:
 *       200:
 *         description: 成功获取用户列表数据
 *         content:
 *           application/json:
 *             example:
 *                code: 200
 *                data: {appId: "wxe5f62bc262ee9106",nonceStr: "0muu1yxqagvm",package: "prepay_id=wx2411271506064603372791b80d09f80000",paySign: "mqaWsvm22U2/zZrFw+jI33FPRDVgtDNiqIZNKNxMxg7phjEAYU3Vt9uNNXgYA8PKNkT8+43JuVCK3IcCCf7Y1cg24IqSrLmn9hL7NxQsQI3pncYv39Hb9Qbey2u1SSgNugCXWWU03JfHQEE3GENJyIPs5nTm/pN5ILWaN7bIFho+g0wlq8sDu92seG5Ji7iH9FQqCo2fJJ5WP7YqFvWxfiMA35f/dP6IJEIxMc3WNUN7zWOZrGybL5ErX1nkOffOpD9SdSEegg9baT3HRA1oiquaveYlf1gL7OjVcyEuaxGldnKG7BS6F0dF5DHxh0eGRNyNHoR1/4w/BYKWvhcDRQ==",signType: "RSA",status: 200,timeStamp: "1682306834"}
 *                message: "下单成功"
 *       403:
 *         description: 参数传递有误
 */
router.post("/pay/placeOrder", placeOrders);

module.exports = router;
